package homework;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

public class FileWriterExample {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("note.txt");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入文本内容（输入 'exit' 结束）：");
        while (true) {
            String input = scanner.nextLine();
            if ("exit".equals(input)) {
                break;
            }
            // 将字符串转换为字节并写入文件
            byte[] bytes = input.getBytes();
            fos.write(bytes);
        }
        fos.close();
        System.out.println("内容已成功写入 ");


    }}
